
ALTER  proc schedule_order_proc_by_line_item_number
@lineItem_number int, @salesOrder_id int, @schedule_date datetime, @user_id varchar(20), @user_group varchar(50)
AS
/*
 * Update the lineItem if scheduleDate is not null
 * Means it is approved by Operations
 */

declare @lineItem_id int
select @lineItem_id = LineItem_ID from customer_open_order_lineitem where COOL_Line_Item_No = @lineItem_number and SalesOrder_ID = @salesOrder_id

if( @schedule_Date <> '' ) 
begin
	/*
	 * Update the Customer_Open_Order_LineItem with all fileds
	 */	
	UPDATE Customer_Open_Order_LineItem SET COOL_Schedule_Date = @schedule_date,
		COOL_Last_Updated_By_ID = @user_id, COOL_Last_Updated_By_Name = @user_id,
		TimeStamp = CURRENT_TIMESTAMP
		WHERE LineItem_ID = @lineItem_id
	
end
else
begin
	/*
	 * Update the Customer_Open_Order_LineItem without scheduled date
	 */	
	UPDATE Customer_Open_Order_LineItem SET COOL_Last_Updated_By_ID = @user_id,
		COOL_Last_Updated_By_Name = @user_id,TimeStamp = CURRENT_TIMESTAMP
		WHERE LineItem_ID = @lineItem_id
	
	
end

exec sp_approve_lineItem @lineItem_id, @salesOrder_Id, @user_id, @user_id,  @user_group, 1



